
<template>
  <div>
    <a-table
      ref="table"
      size="middle"
      rowKey="goodsId"
      :columns="columns"
      :dataSource="dataSource"
      :pagination="pagination"

      @change="handleTableChange"
    >
            <span slot="num" slot-scope="text, record, index">
                {{ (pagination.current-1) * pagination.pageSize + parseInt(index)+1 }}
            </span>
      //此处是给表格最前列添加序号
    </a-table>
  </div>
</template>

<script>
  import {getAction} from '@/api/manage'
  export default {
    data() {
      return {
        //数据源
        dataSource:[],
        //表头
        columns:[
          {
            title: '编号',
            align: 'center',
            scopedSlots: { customRender: 'num' }
          },
         /* {
            title: '编号',//表头名
            align: 'center',
            dataIndex: '',//数据源里的参数名
          },*/
          {
            title: '商品编码',
            align: 'center',
            dataIndex: 'goodsCode'
          },
          {
            title: '商品名称',
            align: 'center',
            dataIndex: 'goodsName'
          },{
            title: '商品型号',
            align: 'center',
            dataIndex: 'goodsModel'
          },{
            title: '商品类别',
            align: 'center',
            dataIndex: 'goodsType.goodsTypeName'
          },{
            title: '商品单位',
            align: 'center',
            dataIndex: 'goodsUnit'
          },{
            title: '采购价格',
            align: 'center',
            dataIndex: 'purchasingPrice'
          },{
            title: '出售价格',
            align: 'center',
            dataIndex: 'sellingPrice'
          },{
            title: '库存下限',
            align: 'center',
            dataIndex: 'minNum'
          },{
            title: '生产厂商',
            align: 'center',
            dataIndex: 'goodsProducer'
          },{
            title: '操作',
            align: 'center',
            dataIndex: ''
          },
        ],
        //分页参数
        pagination:{
          size:'large',
          current: 1,
          pageSize: 5,
          total: 0,
          pageSizeOptions: ['5','10', '20', '30'],//可选的页面显示条数
          showTotal: (total, range) => {
            return range[0] + "-" + range[1] + " 共" + total + "条"
          }, //展示每页第几条至第几条和总数
          hideOnSinglePage: false, // 只有一页时是否隐藏分页器
          showQuickJumper:true, //是否可以快速跳转至某页
          showSizeChanger: true, //是否可以改变pageSize
        },
      }
    },
    created(){
      this.getList()
    },
    methods: {
      //获取列表
      getList(){
        //调用接口获取列表 给你的数据源赋值

        let  url = "/goods/list"
        let parameter={page:this.pagination.current,rows: this.pagination.pageSize};
        getAction(url,parameter).then((res) => {
          console.log(res);
          this.dataSource=res.rows;
          this.pagination.total=res.page.total;
          this.pagination.current=res.page.pageNo;
          this.pagination.pageSize=res.page.pageSize;
          console.log(this.dataSource);

        })
      },
      //表格改变时触发
      handleTableChange(pagination, filters, sorter) {
        this.pagination = pagination;
        this.getList();
      },
    }
  }

</script>